Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-dismissible

Package Overview
Dependencies
Maintainers
11
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-dismissible

Make your components dismissible!

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
304
decreased by-22.45%
Maintainers
11
Weekly downloads
 
Created
Source

Make your components dismissible!

Usage

Example 1: The useDismissible hook

import { useDismissible } from 'react-dismissible'

import { SomeModal } from './some-modal' // not real

function ComfirmButton(props) {
  let [isVisible, setModalVisibiility] = React.useState(false)

  const dismissible = useDismissible({
    onDismiss: () => setModalVisibility(false)
    click: true,  // call onDismiss if clicking outside of this modal
    escape: true, // call onDismiss if the user presses escape
  })

  return (
    <>
      <button {...props} onClick={() => setModalVisiblity(true)} />
      {isVisible && (
        <SomeModal ref={dismissible}>
          <button onClick={() => setModalVisiblity(false)}>Cancel</button>
          <button onClick={props.onClick}>Do it!</button>
        </SomeModal>
      )}
    </>
  )
}

Example 2: The Dismissible component

import { Dismissible } from 'react-dismissible'

import { SomeModal } from './some-modal' // not real

function ComfirmButton(props) {
  let [isVisible, setModalVisibiility] = React.useState(false)

  return (
    <>
      <button {...props} onClick={() => setModalVisiblity(true)} />
      {isVisible && (
        <SomeModal>
          <Dismissible
            click // call onDismiss if clicking outside of this modal
            escape // call onDismiss if the user presses escape
            onDismiss={() => {
              setModalVisibility(false)
            }}
          >
            <button onClick={() => setModalVisiblity(false)}>Cancel</button>
            <button onClick={props.onClick}>Do it!</button>
          </Dismissible>
        </SomeModal>
      )}
    </>
  )
}

Dismissible Props

interface DismissibleProps {
  onDismiss: Function
  click?: boolean
  escape?: boolean
  disabled?: boolean
  document?: Document
  allowClickPropagation?: boolean
}

Keywords

FAQs

Package last updated on 15 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc